﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vowei.Core.Models;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace Vowei.Core.Models
{
    [Serializable]
    public class ResourceAssignment : ITable, ICalendarException, ISerializable
    {
        public ResourceAssignment()
        {
            ID = Guid.NewGuid();
            Exceptions = new List<ExceptionPeriod>();
        }

        protected ResourceAssignment(SerializationInfo info, StreamingContext context)
        {
            Exceptions = (List<ExceptionPeriod>)info.GetValue("Exceptions", typeof(List<ExceptionPeriod>));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Exceptions", Exceptions);
        }

        [Display(Name = "资源")]
        public Guid ResourceId { get; set; }

        [Display(Name = "项目编号")]
        public Guid ProjectId { get; set; }
        
        [Display(Name = "工时日历")]
        public ResourceCalendar WorkCalendar { get; set; }

        public Guid WorkCalendarId { get; set; }

        [Display(Name = "工时成本")]
        public float CostPerHour { get; set; }
        
        public Guid ID
        {
            get;
            set;
        }

        public List<ExceptionPeriod> Exceptions { get; protected set; }

        public ICalendarException Except(ExceptionPeriod period)
        {
            Exceptions.Add(period);
            return this;
        }
    }
}
